﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TUDifier_2
{
    public partial class FindForm : Form
    {
        public bool caseSensitive = false;
        string searchFor = null;
        public ListView gamesList;
        int searchBy = 0;

        
        public FindForm()
        {
            InitializeComponent();
        }

        private void findButton_Click(object sender, EventArgs e)
        {
            if (gameNameRadioButton.Checked == true)
                searchBy = 0;
            else
                searchBy = 1;

            searchFor = searchTextBox.Text;

            if (searchFor != null)
            {
               // mainForm.
               // mainForm.displayFound(searchListView(0, searchFor, searchBy));
            }
            else
            {
                MessageBox.Show("No search Text entered", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        

        private int searchListView(int startFrom, string searchText, int searchBy)
        {
            caseSensitive = caseSensitiveCheckBox.Checked;
            int indexFound = -1;

            if (caseSensitive == true)
            {
                for(int i = startFrom; i < gamesList.Items.Count; i ++)
                {
                    if (searchBy == 0)
                    {
                        if (gamesList.Items[i].SubItems[0].Text == searchText)
                        {
                            indexFound = i;
                        }
                    }
                    else
                    {
                        if (gamesList.Items[i].SubItems[1].Text == searchText)
                        {
                            indexFound = i;
                        }
                    }
                }
            }
            else
            {
                searchText = searchText.ToUpper();
                for (int i = startFrom; i < gamesList.Items.Count; i++)
                {
                    if (searchBy == 0)
                    {
                        if (gamesList.Items[i].SubItems[0].Text.ToUpper() == searchText)
                        {
                            indexFound = i;
                        }
                    }
                    else
                    {
                        if (gamesList.Items[i].SubItems[1].Text.ToUpper() == searchText)
                        {
                            indexFound = i;
                        }
                    }
                }

            }

            return indexFound;

        }
    }
}
